﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace Shared
{
    /// <summary>
    /// A helper class to get and set information about current client context
    /// </summary>
    public static class ClientContextHelper
    {
        #region Public Methods
        
        /// <summary>
        /// Gets the current client ID.
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentClientID()
        {
            // read from operation context or session
            string clientID = string.Empty;
            if (OperationContext.Current != null && OperationContext.Current.IncomingMessageProperties.ContainsKey(CustomHeaderConstants.ClientIDKey))
            {
                clientID = OperationContext.Current.IncomingMessageProperties[CustomHeaderConstants.ClientIDKey].ToString();
            }
            else
            {
                // TODO read from session
            }

            return clientID;
        }

        /// <summary>
        /// Sets the current client ID.
        /// </summary>
        /// <param name="clientID">The client ID.</param>
        public static void SetCurrentClientID(string clientID)
        {
            if (OperationContext.Current != null)
            {
                OperationContext.Current.IncomingMessageProperties[CustomHeaderConstants.ClientIDKey] = clientID;
            }
            else
            {
                //TODO add to session
            }
        }

        #endregion
    }
}
